﻿//-----------------------------------------------------------------------
// <copyright file="UsageRegistry.cs" company="Redmist">
//     Copyright (c) Damien T Smith. All rights reserved.
// </copyright>
// <author>Damien Smith</author>
//-----------------------------------------------------------------------

namespace Redmist.UsageMonitor.Controller
{
    using System.Windows.Forms;
    using Microsoft.Win32;

    /// <summary>Adds and removes the auto start entry to the registry for the application.</summary>
    public static class UsageRegistry
    {
        /// <summary>A System.String representing the key name in the registry.</summary>
        private const string ApplicationName = "aaNet Usage Monitor";

        /// <summary>A System.String representing the auto-run subkey for the current user in the registry.</summary>
        private const string RegistrySubKey = @"Software\Microsoft\Windows\CurrentVersion\Run";

        /// <summary>Adds the path to the current application to the auto-run section in the system registry.</summary>
        public static void CreateAutorunEntry()
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RegistrySubKey, true))
            {
                key.SetValue(ApplicationName, Application.ExecutablePath);
            }
        }

        /// <summary>Removes the current application from the auto-run section in the system registry.</summary>
        public static void DeleteAutorunEntry()
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(RegistrySubKey, true))
            {
                key.DeleteValue(ApplicationName, false);
            }
        }
    }
}
